package game.frame;

import java.awt.Color;
import java.awt.Graphics2D;
import java.util.Random;

public class SnakeFood {
	private int x;
	private int y;
	protected CellPoint food = null;
	protected WorkPanelIfc wpIfc = null;

	protected static final Color snakeFoodColor1 = Color.ORANGE;
	protected static final Color snakeFoodColor2 = Color.YELLOW;

	public SnakeFood(WorkPanelIfc wpIfc) {
		this.wpIfc = wpIfc;
		
		setRandomPosition(wpIfc);
	}
	
	public void setRandomPosition(WorkPanelIfc wpIfc) {
		Random r = new Random();
		int maxX = wpIfc.getWidth() / wpIfc.getCellSize() - 1;
		int maxY = wpIfc.getHeight()/ wpIfc.getCellSize() - 1;
		
		this.x = r.nextInt(maxX);
		this.y = r.nextInt(maxY);
		
		food = new CellPoint(x, y, snakeFoodColor1, wpIfc);
	}
	
	public void drawFood(Graphics2D g2D) {
		food.drawCellPoint(g2D, wpIfc, false);
	}

	public void setChangeColor() {
		if(food.getColor().equals(snakeFoodColor1)) {
			food.setColor(snakeFoodColor2);
		}
		else if(food.getColor().equals(snakeFoodColor2)) {
			food.setColor(snakeFoodColor1);
		}
	}

	public CellPoint getFood() {
		return food;
	}

	public void setFood(CellPoint food) {
		this.food = food;
	}
}
